const { MongoDataSource } = require("apollo-datasource-mongodb");

class Articles extends MongoDataSource {
  // 查询
  getArticles(options) {
    return this.model.find().skip(options.offset).limit(options.limit);
  }

  // 查询文章数量
  getArticleCount() {
    return this.model.countDocuments();
  }

  // 创建
  createArticle(data) {
    const article = new this.model(data);
    // 让mongoose查询author并将其填充到article中
    // article.populate("author").execPopulate();
    return article.save();
  }
}

module.exports = Articles;
